// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#include <cantor/function/scalar_function.h>

namespace cantor {
    std::shared_ptr<cantor::pb::catalog::FunctionDefine> ScalarFunctionBuilder::make_function_def_impl(pb::TypeInfo &&ret, std::vector<pb::TypeInfo> &&args,
                                                                      cantor::pb::catalog::FunctionFeature f,
                                                                      std::string_view func_name,
                                                                      const std::vector<std::string> &names,
                                                                      std::string_view description) {
        auto r = std::make_shared<cantor::pb::catalog::FunctionDefine>();
        *r->mutable_ret_type() = std::move(ret);
        r->mutable_args()->Reserve(args.size());
        for (size_t i = 0; i < args.size(); ++i) {
            *r->mutable_args()->Add() = std::move(args[i]);
        }
        r->set_func_name(func_name.data(), func_name.size());
        r->set_description(description.data(), description.size());
        r->mutable_names()->Reserve(names.size());
        for (size_t i = 0; i < names.size(); ++i) {
            r->mutable_names()->Add()->assign(names[i].data(), names[i].size());
        }
        r->set_feature(f);
        r->set_is_variadic(false);
        return r;
    }
} // namespace cantor
